package com.zj.sa_token.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zj.sa_token.entity.UserInfoEntity;
import com.zj.sa_token.mapper.UserInfoMapper;
import com.zj.sa_token.service.UserInfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import java.util.List;
import java.util.Map;

/**
 * @author li
 * @date 2024-01-12 11:03:58
 *
 * @description 
 */
@Service
@RequiredArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfoEntity> implements UserInfoService {
    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public Page<UserInfoEntity> get(int pageNum, int pageSize,UserInfoEntity userInfoEntity) {
        Page<UserInfoEntity> startPage = PageHelper.startPage(pageNum, pageSize, true);
            userInfoMapper.selectList(getQuery(userInfoEntity));
        return startPage;
    }

    @Override
    public UserInfoEntity getUserInfoByUserName(String username) {
        UserInfoEntity userInfoEntity = userInfoMapper.getUserInfoByUserName(username);
        return userInfoEntity;
    }

    @Override
    public List<Map> getUserInfoByUserNameList(String userName) {
        List<Map> list = userInfoMapper.getUserInfoByUserNameList(userName);
        return list;
    }


    public LambdaQueryWrapper<UserInfoEntity> getQuery(UserInfoEntity userInfoEntity) {
        LambdaQueryWrapper<UserInfoEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(userInfoEntity.getId()), UserInfoEntity::getId, userInfoEntity.getId());
                wrapper.eq(StringUtils.isNotBlank(userInfoEntity.getPassword()), UserInfoEntity::getPassword, userInfoEntity.getPassword());
            wrapper.eq(StringUtils.isNotBlank(userInfoEntity.getRole()), UserInfoEntity::getRole, userInfoEntity.getRole());
            wrapper.eq(StringUtils.isNotBlank(userInfoEntity.getUserName()), UserInfoEntity::getUserName, userInfoEntity.getUserName());
        return wrapper;
    }
}

